home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_08_07
/
8n07137b
< prev
next >
Wrap
Text File
|
1990-06-17
|
877b
|
38 lines
float
read_MSBIN_float(FILE *fp);
/* read a 4 byte MSBIN float from file fp
and convert to internal format
*/
{
unsigned char org_data[4];
int negative;
double mantissa;
double exponent;
double return_value;
/* get data */
fread(org_data, sizeof(org_data), 1, fp);
/* get exponent form msb */
exponent = (double) org_data[0];
/* get sign bit from bit 23 */
negative = (org_data[1] & 0x80) == 0x80;
/* Generate mantissa from ls 23 bits */
mantissa = ((double) (((long) (org_data[1] & 0x7f)) << 16));
mantissa += ((double) (((long) org_data[2] << 8));
mantissa += ((double) ((long) org_data[3]));
/* normalize mantissa */
mantissa = mantissa / pow(2.0, 23.0);
/* Generate full value */
return_value = mantissa * pow(2.0, exponent);
/* adjust for sign */
if (negative) return_value = -return_value;
return ((float) return_value);
}